package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAnswerService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestController
@RequestMapping("answers")
public class AnswerController {

    @Autowired
    private IAnswerService answerService;

    @PostMapping("/save")
    public JSONResult save(Answer answer){
        answerService.save(answer);
        return new JSONResult();
    }





    @GetMapping("/{questionId}")
    public PageInfo selectForListByQuestionId(@PathVariable Long questionId, QueryObject qo){
        //按照创建时间倒序
        qo.setOrderBy("q.createTime desc");
        return answerService.query(questionId, qo);
    }

}
